package xuhaijia.lanou3g.autohome.forum.forumreusing;
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//                  \./                   \\`.
//        .'//            为什么坚持  想一想当初             \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-.  \\`.
//    .'//.-"                 `-.  |  .-'                 "-. \\`.
//  .'//______.============-..   \ | /   ..-============._______\\`.
//.'//____________________________\|/_____________________________\\`.
// 
//                             

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import xuhaijia.lanou3g.autohome.R;
import xuhaijia.lanou3g.autohome.base.NetTool;

/**
 * Created by 7 on 16/8/17.
 */
public class JxRecAdapter extends BaseAdapter{
    ListViewBean listViewBean;
    Context context;


    public JxRecAdapter(Context context) {
        this.context = context;
    }

    public void setListViewBean(ListViewBean listViewBean) {
        this.listViewBean = listViewBean;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (listViewBean == null) {
            return 0;
        }
        return listViewBean.getResult().getList().size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        NetTool mNetTool = new NetTool();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_jxrec,null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        ListViewBean.ResultBean.ListBean bean = listViewBean.getResult().getList().get(position);
        try {
            mNetTool.getImage(bean.getSmallpic(),viewHolder.iv);
            viewHolder.titleTv.setText(bean.getTitle());
            viewHolder.typeTv.setText(bean.getBbsname());
            viewHolder.historyTv.setText(bean.getReplycounts() + "回");
        } catch (NullPointerException e) {

        }

        return convertView;
    }

    private class ViewHolder {
        ImageView iv;
        TextView titleTv;
        TextView typeTv;
        TextView historyTv;

        public ViewHolder(View view) {
            iv = (ImageView) view.findViewById(R.id.jxrec_iv);
            titleTv = (TextView) view.findViewById(R.id.jxrec_title);
            typeTv = (TextView) view.findViewById(R.id.jxrec_type);
            historyTv = (TextView) view.findViewById(R.id.jxrec_history);
        }
    }
}
